package com.huike.report.mapper;

import java.util.Map;

import org.apache.ibatis.annotations.Param;

import com.huike.clues.domain.vo.IndexStatisticsVo;
import org.apache.ibatis.annotations.Select;

/**
 * 首页统计分析的Mapper
 * @author Administrator
 *
 */
public interface ReportMapper {
	/**=========================================基本数据========================================*/
	/**
	 * 获取线索数量
	 * @param beginCreateTime	开始时间
	 * @param endCreateTime		结束时间
	 * @param username			用户名
	 * @return
	 */
	Integer getCluesNum(@Param("startTime") String beginCreateTime,
						@Param("endTime") String endCreateTime,
						@Param("username") String username);

	/**
	 * 获取商机数量
	 * @param beginCreateTime	开始时间
	 * @param endCreateTime		结束时间
	 * @param username			用户名
	 * @return
	 */
	Integer getBusinessNum(@Param("startTime") String beginCreateTime,
						   @Param("endTime") String endCreateTime,
						   @Param("username") String username);

	/**
	 * 获取合同数量
	 * @param beginCreateTime	开始时间
	 * @param endCreateTime		结束时间
	 * @param username			用户名
	 * @return
	 */
	Integer getContractNum(@Param("startTime") String beginCreateTime,
						   @Param("endTime") String endCreateTime,
						   @Param("username") String username);

	/**
	 * 获取合同金额
	 * @param beginCreateTime	开始时间
	 * @param endCreateTime		结束时间
	 * @param username			用户名
	 * @return
	 */
	Double getSalesAmount(@Param("startTime") String beginCreateTime,
						  @Param("endTime") String endCreateTime,
						  @Param("username") String username);
	/**=========================================今日简报========================================*/

	Integer getTodayCluesNum(@Param("username") String username,@Param("nowDate") String nowDate);

	Integer getTodayBusinessNum(@Param("username") String username,@Param("nowDate") String nowDate);

	Integer getTodayContractNum(@Param("username") String username,@Param("nowDate") String nowDate);

	Double getTodaySalesAmount(@Param("username") String username,@Param("nowDate") String nowDate);

	/**=========================================待办========================================*/
	@Select("select count(*) from tb_clue c,tb_assign_record a WHERE a.user_name =#{username} AND date_format(a.create_time, '%Y-%m-%d') BETWEEN date_format(#{beginCreateTime}, '%Y-%m-%d') and date_format(#{endCreateTime}, '%Y-%m-%d') and c.`status` = 1 and a.type=0 and c.id=a.assign_id")
	Integer getTofollowedCluesNum(@Param("username") String username,@Param("beginCreateTime") String beginCreateTime, @Param("endCreateTime") String endCreateTime);

	Integer getToallocatedCluesNum(@Param("username") String username,@Param("beginCreateTime") String beginCreateTime, @Param("endCreateTime") String endCreateTime);
	@Select("select count(*) from tb_business b,tb_assign_record a WHERE a.user_name =#{username} AND date_format(a.create_time, '%Y-%m-%d') BETWEEN date_format(#{beginCreateTime}, '%Y-%m-%d') and date_format(#{endCreateTime}, '%Y-%m-%d') and b.`status` = 1 and a.type=1 and b.id=a.assign_id")
	Integer getTofollowedBusinessNum(@Param("username") String username,@Param("beginCreateTime") String beginCreateTime, @Param("endCreateTime") String endCreateTime);

	Integer getToallocatedBusinessNum(@Param("username") String username,@Param("beginCreateTime") String beginCreateTime, @Param("endCreateTime") String endCreateTime);
}
